
package ct.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import ct.model.Obligation;

public class FenetreAjoutObligation extends JFrame implements ActionListener{

	private static final long serialVersionUID = 1L;
	private FormulaireObligation form;
	private PanelPortefeuille portef;

	public FenetreAjoutObligation(PanelPortefeuille portef){
		super("Ajout d'une obligation");
		this.setSize(400, 250);
		this.setLocationRelativeTo(null);
		this.setAlwaysOnTop(true);
		
		this.portef = portef;
		form = new FormulaireObligation();
		JPanel boutonpanel = new JPanel(new FlowLayout());
		
		JButton Bajout = new JButton("Ajouter");
		Bajout.addActionListener(this);
		boutonpanel.add(Bajout);
		
		JPanel content = new JPanel(new BorderLayout());
		content.add(form,BorderLayout.CENTER);
		content.add(boutonpanel,BorderLayout.SOUTH);
		
		this.setContentPane(content);
	}

	public void actionPerformed(ActionEvent e) {
		Obligation o = form.getObligation();
		if (o!=null){
			portef.getPortefeuille().addObligation(o);
			portef.MAJ();
			this.dispose();
		}
		
	}
	
}
